package com.easy.controller;

import com.easy.bean.Pattern;
import com.easy.service.PatternService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/pattern")
@CrossOrigin
public class PatternController {
    @Autowired
    PatternService patternService;
    @PostMapping
    public Result add(@RequestBody Pattern pattern){
        Object obj= patternService.add(pattern);
        return Result.success(obj);
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Integer id){
        int obj= patternService.del(id);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody Pattern pattern){
        Object obj= patternService.edit(pattern);
        return Result.success(obj);
    }

    @GetMapping("list")
    public Result list(Pattern pattern){
        Object obj= patternService.all(pattern);
        return Result.success(obj);
    }

    @GetMapping("{id}")
    public Result select(@PathVariable("id") Integer id){
        Object obj= patternService.one(id);
        return Result.success(obj);
    }
    @GetMapping("page")
    public Result page(Page page, Pattern pattern){
        patternService.page(page,pattern);
        return Result.success(page);
    }


}
